package com.zjs.practice.service.impl;

import com.zjs.practice.mapper.MysqlPracticeMapper;
import com.zjs.practice.service.RedisPracticeService;
import com.zjs.practice.domain.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Redis练习
 * @author zhu
 * @version 1.0
 * @date 2021/1/30 14:35
 */
@Slf4j
@Service
@Transactional
public class RedisPracticeServiceImpl implements RedisPracticeService {

    @Resource
    private RedisTemplate<String, String> redisTemplate;

    @Resource
    private MysqlPracticeMapper mapper;

    /**
     * redis充值订单锁的key值
     */
    private static final String VLOAD_LOCK = "NODE_LS:VLOAD:LOCK_";

    @Override
    public Message test() {
        String updateFlag = redisTemplate.opsForValue().get(VLOAD_LOCK + "11111");
        if (!"1".equals(updateFlag)) {
            // 没有抢到锁直接返回
            log.info("redis键值：{}", updateFlag);
        }
        return Message.ok();
    }

}
